/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package physical_spaces.DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.faces.context.FacesContext;
import login.bean.LoginBean;

/**
 *
 * @author chucho
 */
public class PhysicalSpaceDAO {
    Connection connection;
    private LoginBean lb ;
    
    public PhysicalSpaceDAO() {
        lb = (LoginBean) FacesContext.getCurrentInstance()
                .getExternalContext().getSessionMap().get("loginBean");
        this.connection = lb.getCurrentConnection();
    }
    
    public void set(String variable,String value) throws SQLException{
        String sql = "SET GLOBAL "+variable+" = "+value;
        System.out.println("COMANDO: " + sql);
        Statement statement = connection.createStatement();
        
        int res = statement.executeUpdate(sql);
        System.out.println("RESULTADO: "+ res);
        
    }
    
    public ResultSet getGlobalVariables() throws SQLException{
        String sql = "SHOW GLOBAL VARIABLES";
        Statement statement = connection.createStatement();
        return statement.executeQuery(sql);
    }
}
